<%@ page contentType="text/html; charset=UTF-8" %>
<%
	String contextPath = request.getContextPath();
%>
<html>
<head>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xpage.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xlist.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xtree.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xmenu.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xrept.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xtabs.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xpops.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xcard.css" type="text/css"/>
<link rel=stylesheet href="<%=contextPath%>/jsl/styles/xtime.css" type="text/css"/>
<script src="<%=contextPath%>/jsl/script/xcomm.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xview.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xtabs.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xtree.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xlist.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xcard.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xmenu.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xrept.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xpops.js" type="text/javascript"></script>
<script src="<%=contextPath%>/jsl/script/xtime.js" type="text/javascript"></script>
<script type="text/javascript">
var tabs = null;
var list = null;
var tree = null;
window.onload = function(){
	document.body.onselectstart = function(){
		return false;
	};
	document.oncontextmenu = function(){
        return false;
	};
	buildWorkBench();
};

function buildWorkBench(){
	tabs = new Tabs("<%=contextPath%>",document.getElementById("middleBar"));
	tabs.functionId = "301";
	tabs.menuClickHandler = handleMenuClickEvent;
	tabs.refresh();
	tabs.registerEventProcessor("afterClick0",buildFunctionTree);
}

function buildFunctionTree(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="DIV"&&evt.srcElement.offsetWidth-evt.offsetX<15){
		var funcExtendedDiv = document.getElementById("functionExtendedDiv");
		if(!funcExtendedDiv){
			funcExtendedDiv = document.createElement("div");
			document.body.appendChild(funcExtendedDiv);
			funcExtendedDiv.style.position = "absolute";
			funcExtendedDiv.name = "extendeddiv";
			funcExtendedDiv.id = "functionExtendedDiv";
			funcExtendedDiv.style.border = "1px solid black";
			funcExtendedDiv.style.backgroundColor = "white";
			funcExtendedDiv.style.width = "170px";
			tree = new Tree("<%=contextPath%>",funcExtendedDiv);
			var requestObject = Comm.buildRequestObject("query","OID,NAME,FUNID,PARENTID,(SELECT COUNT(A.OID) FROM BAS_FUNCTION A WHERE A.PARENTID=BAS_FUNCTION.FUNID AND ISNULL(A.RIGHTKEY)) AS HASCHILDREN",null,"BAS_FUNCTION",null,"BAS_FUNCTION.PARENTID=-1",null,null,null,null);
			tree.dataModel = window["Comm"].sendRequest("<%=contextPath%>",requestObject);
			tree.refresh();
			tree.lastRequestObject = requestObject;
			tree.registerEventProcessor("afterClick0",clickFunctionTree);
			funcExtendedDiv.style.top = (handleObject.getBoundingClientRect().top+28)+"px";
			funcExtendedDiv.style.left = (handleObject.getBoundingClientRect().right-173)+"px";
		}
		if(funcExtendedDiv.style.display!="block"){
			funcExtendedDiv.style.display = "block";
			tabs.divContainer.className = "xtabscollapse";
		}else{
			funcExtendedDiv.style.display = "none";
			tabs.divContainer.className = "xtabs";
		}
	}
}

function clickFunctionTree(evt){
	var tagName = evt.srcElement.tagName;
	if(tagName=="FONT"){
		buildFunctionContent(evt);
	}
}

function buildFunctionContent(evt){
	var handleObject = evt.srcElement.parentElement.parentElement;
	if(handleObject[tree.hasChildrenField]>0)return;
	tabs.addTab(evt.srcElement.innerText);
	var funId = handleObject.FUNID;
	var divMiddleContainer = document.getElementById("middleDivContent");
	if(funId=="201"){
		var rept = new Rept("<%=contextPath%>",divMiddleContainer);
		rept.refresh();
	}else{
		var templateName = "";
		var tableName = "";
		if(funId=="102"){
			templateName = "tableFieldList";
			tableName = "BAS_TABLEFIELD";
		}else if(funId=="103"){
			templateName = "fieldRightList";
			tableName = "BAS_FIELDRIGHT";
		}else if(funId=="104"){
			templateName = "tableTemplateList";
			tableName = "BAS_TEMPLATEFIELD";
		}else if(funId=="105"){
			templateName = "userList";
			tableName = "BAS_USER";
		}
		if(list===null){
			list = new List("<%=contextPath%>",divMiddleContainer);
			tabs.subComponents.push(list);
		}
		var requestObject = Comm.buildRequestObject("query",null,templateName,tableName,null,null,null,0,12,null);
		list.dataModel = window["Comm"].sendRequest("<%=contextPath%>",requestObject);
		list.refresh();
		list.functionId = handleObject.FUNID;
		list.lastRequestObject = requestObject;
		list.menuClickHandler = handleMenuClickEvent;
	}
}



function handleMenuClickEvent(evt){
	var handleObject = evt.srcElement;
	var funId = handleObject.FUNID;
	if(funId=="10201"){
		list.insertListRow("tableFieldList");
	}else if(funId=="10202"){
		list.updateSelectedListRow("tableFieldList");
	}else if(funId=="10203"){
		list.deleteSelectedListRow();
	}else if(funId=="10204"){
		list.exportExcel("tableRelationList.xls");
	}else if(funId=="10301"){
		list.insertListRow("fieldRightList");
	}else if(funId=="10302"){
		list.updateSelectedListRow("fieldRightList");
	}else if(funId=="10303"){
		list.deleteSelectedListRow();
	}else if(funId=="10304"){
		list.exportExcel("fieldRight.xls");
	}else if(funId=="10401"){
		list.insertListRow("tableTemplateList");
	}else if(funId=="10402"){
		list.updateSelectedListRow("tableTemplateList");
	}else if(funId=="10403"){
		list.deleteSelectedListRow();
	}else if(funId=="10404"){
		list.exportExcel("tableTemplate.xls");
	}else if(funId=="10501"){
		list.insertListRow("userList");
	}else if(funId=="10502"){
		list.updateSelectedListRow("userList");
	}else if(funId=="10503"){
		list.deleteSelectedListRow();
	}else if(funId=="10504"){
		list.exportExcel("userList.xls");
	}else if(funId=="30101"){
		tabs.closeCurTab();
	}else if(funId=="30102"){
		tabs.closeOtherTab();
	}else if(funId=="30103"){
		tabs.closeAllTab();
	}else{
		Comm.showAlert("<%=contextPath%>","common.tip.nohandleaction",null,null);
	}
}
</script>
</head>
<body>
<div class="top" id="topDiv"><div id="topDivContent"></div></div>
<div class="left" id="leftDiv"><div class="bar" id="leftBar"></div><div id="leftDivContent"></div></div>
<div class="right" id="rightDiv"><div class="bar" id="rightBar"></div><div id="rightDivContent"></div></div>
<div class="middle" id="middleDiv"><div class="middlebar" id="middleBar"></div><div class="interval"></div><div id="middleDivContent" style="height:96%;width:100%;overflow:hidden"></div></div>
<div class="bottom" id="bottomDiv"><div id="bottomDivContent"></div></div>
</body>
</html>